<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class DBShardingsphereTestFindCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shardingsphere:find';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test Shardingsphere Find in Shop DB';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $conn=DB::connection("shop");
        echo "Rows=".DB::connection("shardingsphere")->table("member")->count().'\r\n';
        DB::connection("shardingsphere")->table("member")->orderBy("member_id", 'asc')->chunk(100,function($addrs)use($conn){
            foreach($addrs as $addr){
             $enc=$conn->table("member")->where('member_id',$addr->member_id)->first();
             echo <<<EOL
              |【Enc-username】: {$enc->username}\r\n
              |【Enc-Mobile】： {$enc->mobile}\r\n
              |【Enc-nickname】： {$enc->nickname}\r\n
              |【Enc-realname】: {$enc->realname}\r\n
              |【Dec-username】: {$addr->username}\r\n
              |【Dec-Mobile】： {$addr->mobile}\r\n
              |【Dec-nickname】： {$addr->nickname}\r\n
              |【Dec-realname】: {$addr->realname}\r\n
              ===========================================\r\n
             EOL;
            }
        });
        return 0;
    }
}
